package com.taobaolite.user.guest;

import com.taobaolite.cart_has_items.CartHasItems;
import com.taobaolite.history.History;
import com.taobaolite.order.Order;
import com.taobaolite.user.User;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name = "guest")
public class Guest {
    @Id
    private Long guestId;


    @OneToOne(cascade = CascadeType.ALL)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @MapsId
    @JoinColumn(name = "guestId")
    private User user;

    private String name;

    public Set<Order> getOrderSet() {
        return orderSet;
    }

    public void setOrderSet(Set<Order> orderSet) {
        this.orderSet = orderSet;
    }

    @OneToMany(mappedBy = "guest",cascade = CascadeType.ALL)
    @OnDelete(action = OnDeleteAction.NO_ACTION)
    private Set<Order> orderSet;

    @OneToMany(cascade = CascadeType.ALL)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "guestId")
    private Set<CartHasItems> cartHasItems;

    @OneToMany(cascade = CascadeType.ALL)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "userId")
    private Set<History> history;

    public Set<History> getHistory() {
        return history;
    }

    public void setHistory(Set<History> history) {
        this.history = history;
    }

    public Set<CartHasItems> getCartHasItems() {
        return cartHasItems;
    }

    public void setCartHasItems(Set<CartHasItems> cartHasItems) {
        this.cartHasItems = cartHasItems;
    }

    public void setGuestId(Long guestId) {
        this.guestId = guestId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Long getGuestId() {
        return guestId;
    }

    public String getName() {
        return name;
    }

    public User getUser() {
        return user;
    }

    public Guest(User user, String name) {
        this.name = name;
        this.user = user;
    }

    public Guest() {}
}
